package com.zhika.zishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.zhika.zishi.R;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/24.
 */
public class LikeStrategyPictureAdapter extends BaseAdapter {

    private ArrayList<String> pictureUrlList;

    private Context context;

    public LikeStrategyPictureAdapter(Context context,ArrayList<String> pictureUrlList){
        this.context = context;
        this.pictureUrlList = pictureUrlList;
    }

    @Override
    public int getCount() {
        return pictureUrlList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_of_like_strategy_picture,null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) view.findViewById(R.id.item_of_like_strategy_picture_image_view);

            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
            resetViewHolder(viewHolder);
        }

        //根据URL从网络上下载图片
        String urlStr = pictureUrlList.get(position);

        viewHolder.imageView.setImageResource(R.drawable.ic_launcher);

        return view;

    }

    private void resetViewHolder(ViewHolder viewHolder){
        viewHolder.imageView.setImageBitmap(null);
    }

    private class ViewHolder{

        private ImageView imageView;

    }
}
